@extends("h5.layouts.main")
@section('content')
    <?php

    use App\Models\Admin\OrderTempModel;
    use App\admin\Service\OA;
    use App\Models\Admin\OrderBaleModel;
    use App\Models\User\UserModel;
    use App\Jobs\Fun;
    use App\Models\CompanysModel;
    use App\Models\User\UserOrdersModel;
    //CompanysModel::where('uid',$t['cid'])->value('com_name')

    $out_trade_no = $_GET['out_trade_no'] ?? '';
    if ($out_trade_no == '') {
        Fun::showmsg("参数错误");
    }
    $orderTempModel = OrderTempModel::where(['out_trade_no' => $out_trade_no])->first();
    if (!$orderTempModel) {
        Fun::showmsg("订单不存在");
    }
    $out_trade_no=$orderTempModel->out_trade_no;
    $uid = OA::$user->getId();
    $type = null; ///gs表示公司  gc 表示工厂
    if ($orderTempModel->cid == $uid) {
        $type = 'gs';    ///表示公司
    } elseif ($orderTempModel->fid == $uid) {
        $type = 'gc';    ///表示工厂
    } else {
        Fun::showmsg("您无权限操作表单");
    }
    $OrderBaleModel = OrderBaleModel::where('id', $orderTempModel->bale)->first();
    if (!$OrderBaleModel) {
        Fun::showmsg("订单不存在");
    }
    $order = UserOrdersModel::with('orderFactory')->with('orderDetail')->with('orderCompany')->where('order_no', $orderTempModel->out_trade_no)->first();
    if (!$order) {
        Fun::showmsg("订单不存在");
    }

    $yuanliao='';
    if($type=='gs'||$order['yuanliao_time']!=0){///如果是公司,则显示出原料,或者原料已经被设置为发送
        $yuanliao=$order['yuanliao'];
    }

    ?>
    <link rel="stylesheet" type="text/css" href="../datepicker/jquery-ui.min.css">
    <link rel="stylesheet" type="text/css" href="../css/app.css">
    <link rel="stylesheet" type="text/css" href="../css/orderGrad.css">
    <script src="http://g.tbcdn.cn/mtb/lib-flexible/0.3.4/??flexible_css.js,flexible.js"></script>
    <input id="out_trade_no" value="<?= $orderTempModel->out_trade_no ?>" type="hidden" />
    <input id="yuanliao"  type="hidden" value='<?= $yuanliao ?>'/>
    <input id="status" type="hidden" value="<?= $order->status ?>" />
    <input id="type" type="hidden" value="<?= $type ?>" />
    <!-- 我的订单（抢单和订单） -->
    <div class="orderDockingPage  orderKongzhiPage orderProductionDocumentary">
        <div class="orderParamTitle">
        <span>订单控制器 (<?php
            if ($type == 'gs') {
                echo "公司";
            } else {
                echo "工厂";
            }
            ?>)</span>
            <a onclick="MC.back()" class="back"> <img src="../images/return.png" class="orderRtns"/></a>
        </div>
        <div style="height:1.066667rem"></div>
        <div class="contentdiv ">
            <div class="infodiv clearfix">
                <div class="imgdiv">
                    <img src="<?= $OrderBaleModel->img ?>" class="pic"/>
                </div>
                <div class="infodesc">

                    <p class="p">
                        <span>订单编号: <?= $orderTempModel->out_trade_no ?></span>
                        <span>发单公司: <?= CompanysModel::where('uid', $orderTempModel['cid'])->value('com_name') ?></span>
                        <span>接单工厂: <?= CompanysModel::where('uid', $orderTempModel['fid'])->value('com_name') ?></span>
                    </p>
                </div>
            </div>
            <div class="buttonDiv">
                <a class="button orderInfo" show="orderInfoDiv">订单详情</a>
                <a class="button orderqingdan" show="orderqingdanDiv">原料清单</a>
                <a class="button orderbaogao" href="/h5/order/comCheck.html?out_trade_no=<?= $orderTempModel->out_trade_no ?>">验货报告</a>
                <?php if($type=='gc'&&($order['status']<UserOrdersModel::status_daohuoqianshou)){
                    // <?php if($type=='gc'&&($order['status']<UserOrdersModel::status_daohuoqianshou)){ ?>

                <a class="button orderyunshu" show="orderyunshuDiv">发货运输</a>
                <?php } ?>
                <?php
                    if($order['status']>=UserOrdersModel::status_daohuoqianshou){
                ?>
                <a class="button orderpingjia" href="/h5/order/shippingNewEvaluation.html?out_trade_no=<?= $orderTempModel->out_trade_no ?>">收货评价</a>
                <a class="button ordershouhoufuwu" show="ordershouhoufuwuDiv">售后服务</a>
                <?php } ?>
            <?php if($type=='gs'&&$order['status']!=UserOrdersModel::status_wancheng){ ?>
                <a class="button orderwancheng">订单完成</a>
                <?php } ?>
            </div>
        </div>
        <div class="content orderInfoDiv conDiv">
            <p class="title">订单详情</p>
            <div class="orderCotent">
                <ul>
                    <li>
                        <div>中单企业</div>
                        <div><?= $order['orderFactory']['com_name'] ?? '';  ?></div>
                    </li>
                    <li>
                        <div>企业地址</div>
                        <div><?= $order['orderCompany']['com_address'] ?? ''; ?></div>
                    </li>
                    <li>
                        <div>负责人</div>
                        <div><?= $order['orderFactory']['legal_name'] ?? ''; ?></div>
                    </li>
                    <li>
                        <div>联系方式</div>
                        <div><?= $order['orderFactory']['legal_mobile'] ?? ''; ?></div>
                    </li>
                    <li>
                        <div>订单数量</div>
                        <div><?= $order['num'] ?? 0;  ?></div>
                    </li>
                    <li>
                        <div>订单金额</div>
                        <div>¥<?=  $order['money'] ?? 0; ?>元</div>
                    </li>
                    <li>
                        <div>保证金</div>
                        <div>¥<?=  $order['bond_money'] ?? 0; ?>元</div>
                    </li>
                    <li>
                        <div>订单总价</div>
                        <div>¥<?= $order['num'] * $order['money'];  ?>元</div>
                    </li>
                    <li>
                        <div>厂家备注</div>
                        <div><?= $order['note'] ?? '';  ?></div>
                    </li>
                    <li>
                        <div>下单时间</div>
                        <div><?= $order['created_at'] ? date('Y-m-d H:i:s', $order['created_at']) : ''; ?></div>
                    </li>
                    <li>
                        <div>快递运单</div>
                        <div><?=  $order['kd_code'] ?? '';  ?></div>
                    </li>
                    <li>
                        <div>快递类型</div>
                        <div><?= $order['kd_name'] ?? ''; ?></div>
                    </li>
                    <li>
                        <div>生产进度</div>
                        <div><?=  UserOrdersModel::getStatus($order['status']); ?> </div>
                    </li>
                    <?php /* <li class="custom">
                    <div>自定义属性</div>
                    <div>自定义内容</div> */ ?>
                    </li>
                </ul>

            </div>
            <?php if($type=='gs'&&$order['status']==UserOrdersModel::status_fabaofahuo){ ?>
            <div class="orderDown">
                <div class="divbtn querenshouhuobtn">确认收货</div>
            </div>
            <?php } ?>
        </div>

        <div class="orderqingdanDiv conDiv none">
            <p class="title">原料清单</p>
            <div class="contentdiv">
                <?php if($yuanliao!=''||$type=='gs'){ ?>
                <ul class="ulyuanliao">
                    <li class="first">
                        <span class="title">款号</span>
                        <span class="title jishuan">件数</span>
                        <span class="title">原料名称</span>
                        <span class="title">单位</span>
                        <span class="title">匹/包/卷</span>
                        <span class="title jishuan">单耗</span>
                        <span class="title">损耗</span>
                        <span class="title jishuan">总合计</span>
                    </li>

                </ul>
                <?php }else{
                    echo '<h2 class="h2">公司未发送清单</h2>';
                    }

                if($type=='gs'&&$order['yuanliao_time']==0){ ?>
                <div class="buttonlist">
                    <a class="button addbtn">添加清单</a>
                    <a class="button send_yuanliao">发送给工厂</a>
                </div>
                <?php } ?>
            </div>
        </div>
        <?php if($type=='gc'&&($order['status']<UserOrdersModel::status_daohuoqianshou)){ ?>
        <div class="content orderyunshuDiv conDiv none">
            <p class="title">发货运输</p>
            <div class="contentdiv">
                <div class="orderCotent">
                    <ul>
                        <li>
                            <div>快递运单</div>
                            <div><input type="text" value="<?=  $order['kd_code'] ?? '';  ?>" placeholder="请输入快递运单" class="kd_code inputdiv"/></div>
                        </li>
                        <li>
                            <div>快递类型</div>
                            <div><input type="text" value="<?=  $order['kd_name'] ?? '';  ?>" placeholder="请输入快递类型"  class="kd_name inputdiv"/></div>
                        </li>
                        <li>
                            <div>出发地</div>
                            <div><input type="text" value="<?=  $order['send_address'] ?? '';  ?>" placeholder="请输入出发地"  class="send_address inputdiv"/></div>
                        </li>
                        <li>
                            <div>目的地</div>
                            <div><input type="text" value="<?=  $order['receiving_address'] ?? '';  ?>" placeholder="请输入目的地"  class="receiving_address inputdiv"/></div>
                        </li>
                    </ul>
                </div>

                <div class="orderDown">
                    <?php if(empty($order['kd_time'])){ ?>
                    <div class="divbtn fahuobtn">确认发货</div>
                    <?php }else{
                        echo '<div class="divbtn fahuobtn">确认修改</div>';
                        } ?>
                </div>
            </div>
        </div>
        <?php } ?>


        <?php /*
        <div class="orderbaogaoDiv conDiv">
            <p class="title">跟单验收报告</p>
            <div class="contentdiv">
                @include('h5.order.baogao')
            </div>
        </div> */ ?>
        <?php
        if($order['status']==UserOrdersModel::status_wancheng){
        ?>
        <div class="orderpingjiaDiv conDiv none">
            <p class="title">售后评价</p>
            <div class="contentdiv"></div>
        </div>
        <div class="ordershouhoufuwuDiv conDiv none">
            <p class="title">售后服务</p>
            <div class="contentdiv"></div>
        </div>
    <?php } ?>

    </div>


    <div class="msgboxadd none">
        <div class="contentdiv">
            <ul class="ul">
                <li att="kuanhao"  class="clearfix">
                    <span class="label">款号:</span>
                    <input type="text" value="" class="value "/>
                </li>
                <li att="jianshu" class="clearfix">
                    <span class="label">件数:</span>
                    <input type="number" value="" class="value "/>
                    <span class="desc"></span>
                </li>
                <li att="yuanliao" class="clearfix">
                    <span class="label">原料名称:</span>
                    <input type="text" value="" class="value "/>
                    <span class="desc"></span>
                </li>
                <li att="danwei" class="clearfix">
                    <span class="label">单位:</span>
                    <input type="text" value="" class="value"/>
                    <span class="desc"></span>
                </li>
                <li att="bao" class="clearfix">
                    <span class="label">匹/包/卷:</span>
                    <input type="number" value="" class="value"/>
                    <span class="desc"></span>
                </li>
                <li att="danhao" class="clearfix">
                    <span class="label">单耗:</span>
                    <input type="number" value="" class="value"/>
                    <span class="desc"></span>
                </li>
                <li att="sunhao" class="clearfix">
                    <span class="label">损耗:</span>
                    <input type="number" value="" min="0" max="100" class="value"/>
                    <span class="desc">%</span>
                </li>
            </ul>
            <div class="butarray clearfix">
               <?php if($type=='gs'&&$order['yuanliao_time']==0){ ?>
                <a class="button savebtn">保存</a>
                <a class="button deletebtn buttonred">删除</a>
                 <?php } ?>
                <a class="button closebtn buttonputong">关闭</a>
            </div>
        </div>
    </div>









    <script>
      var kz=new MC.Order.kongzhitai();

    </script>


@stop